#ifndef DevBitmap_First
#define DevBitmap_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Types.h"
#include "Point.h"
#include "Ink.h"
#include "RefCounted.h"

class WindowPort;
class WindowColorMap;
class ColorMapper;

enum BitBltOp {
	eBitCopy,
	eBitOr,
	eBitSet
};

struct BitmapInfo {
public:
	Point extent;
	int bitsperpixel;
	int numcomponents;
	int rowpad;
	int rowlen;
public:
	BitmapInfo(const Point &extent, int depth, int rowpad);
	BitmapInfo(const Point &extent, int bitsperpixel, int numcomponents, int rowpad);
};

//---- DevBitmap ---------------------------------------------------------------

class DevBitmap : public RefCounted {
public:
	Point size;
	u_short depth;
	bool changed;
protected:
	DevBitmap(const Point &sz, u_short depth= 1);
	DevBitmap(DevBitmap *dbm);
	virtual ~DevBitmap();
public:
	MetaDef(DevBitmap);
	virtual int BytesPerLine();
	virtual void SetPixel(u_int x, u_int y, u_long value);
	virtual u_long GetPixel(u_int x, u_int y);
	virtual void SetRow(BitmapInfo *bi, int row, byte *rowdata);
	virtual void GetRow(BitmapInfo *bi, int row, byte *rowdata);
	virtual void SetData(BitmapInfo *bi, void *data);
	virtual void ReadData(BitmapInfo *bi, IStream &is);
	virtual void WriteData(BitmapInfo *bi, OStream &os);
	virtual DevBitmap *MakeCopy();

	virtual DevBitmap *DevAllocBitmap(const Point &s, u_short d);
	virtual void DevBitBlt(int x, int y, int w, int h, BitBltOp op,
					DevBitmap *s, int sx, int sy, u_long val= 0);
	virtual DevBitmap *DevScaleBitmap(const Point &ss);

	virtual void DevHalftone(WindowColorMap *wcm, DevBitmap *spr, ColorMapper *cmapper);
	virtual void DevFloydSteinberg(WindowColorMap *wcm, DevBitmap *spr, ColorMapper *cmapper);
	virtual void DevMapDirect(WindowColorMap *wcm, DevBitmap *dbm, ColorMapper *cmapper);

	const Point &Size()
		{ return size; }
	int Depth()
		{ return depth; }
	int ShortsPerLine()
		{ return ((size.x-1)/16+1)*depth; }

	virtual void DevMapColors(DevBitmap *src, u_long *map);
	virtual DevBitmap *PrepareBitmap(WindowPort *port, const Point &e, ColorMapper*);
	DevBitmap *FindInCache(WindowColorMap *wcm, const Point &scale);
	void AddToCache(DevBitmap *dbm, WindowColorMap *wcm);

	DevBitmap *GetMask(const Point &e, ColorMapper *cmapper);
};

#endif

